<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" media="all">
</head>
<body>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">内容</label>
					<div class="layui-input-inline">
              			<input type="text" id="id" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
           			</div>	
				</div>
		        <div class="layui-inline">
		        	<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
		            	<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
		            </button>
		       	</div>				
			</div>
		</div>
		<div class="layui-card-body">
	        <div style="padding-bottom: 10px;">
	          <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
	          <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
	        </div>
			<table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
	        <script type="text/html" id="table-content-list">
          		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
          		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        	</script>				        		
		</div>
	</div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table'], function(){
        var $ = layui.$,layer = layui.layer,form = layui.form,element = layui.element,table = layui.table;
        form.render('select');
        element.render();
        
        table.render({
            elem: '#LAY-app-content-list'
            ,url: '/product/queryProduct'
//             ,width: admin.screen() > 1 ? 892 : ''
            ,height: 332
            ,cols: [[
              {type:'checkbox', fixed: 'left',}
              ,{field:'id', width:200, title: '商品描述', templet: '#titleTpl'}
              ,{field:'username', width:80, title: '商家'}
              ,{field:'sex', width:80, title: '名称', sort: true}
              ,{field:'city', width:80, title: '商品信息'}
              ,{field:'sign', width: 160, title: '运费'}
              ,{field:'experience', width:80, title: '审核状态', sort: true}
              ,{ title:'操作',width:178, align:'center', fixed: 'right', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page: true
          });
        
        

        form.on('select',function (data) {
            //得到select原始DOM对象
            var dom = data.elem;
            //获得下拉框选中的id
            var id = $(dom).val();
            //获取选中的标记(2二级分类/3三级分类)
            var flag = $(dom).data('flag');
            //获取改变的是哪一个下拉框
            var select = $(dom).data('select');
            //只有下拉框是分类下拉框时才进入此方法
            //如不加判断则所有下拉框都会进入方法，则会报错
            if(select===2){
                $.ajax({
                    url: "/classify/queryClassifyListByAjax",
                    data: {"pid":id,"flag":flag,"type":3},
                    dataType: "json",
                    type: "post",
                    traditional: true,
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data, function (i, v) {
                            html += '<option value="' + v.id + '" hassubinfo="true">' + v.name + '</option>'
                        });
                        if(flag===2){
                            $('.secondClassify').append(html);
                        }else if(flag===3){
                            $('.classfiy').append(html);
                        }
                        form.render();
                    }
                });
            }
        });
        var active = {
            editThis:function (id) {
                //查看
                window.location.href = "/product/productEdit?proId=" + id;
            },
            updateThis:function (id,status) {
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: "/product/handleProductStatus",
                        data: {'id': id,'status':status},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc, {icon: 1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc, {icon: 2})
                            }
                        }
                    })
                })

            },
            applyThis:function (id,examineStatus) {
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: "/product/handleProductStatus",
                        data: {'id': id,'examineStatus':examineStatus},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc, {icon: 1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc, {icon: 2})
                            }
                        }
                    })
                })
            },
            updateBatch:function (group,idArr) {
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: "/product/handleProductStatusBatch",
                        data: {'type': group,'idArr':JSON.stringify(idArr)},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc, {icon: 1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc, {icon: 2})
                            }
                        }
                    })
                })
            }
        };
        //查看或编辑事件触发
        $(".editThis").on('click',function () {
            var type = $(this).data('type');
            var id = $(this).data('id');
            active[type] && active[type].call(this,id);
        });
        //下架或删除事件触发
        $(".updateThis").on('click',function () {
            var type = $(this).data('type');
            var id = $(this).data('id');
            var status = $(this).data('status');
            active[type] && active[type].call(this,id,status);
        });
        //审核事件触发
        $(".applyThis").on('click',function () {
            var type = $(this).data('type');
            var id = $(this).data('id');
            var examineStatus = $(this).data('status');
            active[type] && active[type].call(this,id,examineStatus);
        });
        //全选按钮视觉效果
        $(".check-all").on('click',function () {
            var idArr = [];
            $(".check-input").each(function (i,v) {
                idArr.push(v.value);
                $(this).prop("checked",true);
            });
            form.render();
        });
        //批量事件
        $(".updateBatch").on('click',function () {
            var group = $(this).data('group');
            var type = "updateBatch";
            var idArr = "";
            $(".check-input").each(function (i,v) {
                if(v.checked){
                    idArr += parseInt(v.value) + ",";
                }
            });
            idArr = idArr.substr(0,idArr.length-1);
            active[type] && active[type].call(this,group,idArr);
        });
    });

    /* 表格内下拉 */
    function downTd(id, num) {
        var down;
        var sdfdf;
        if (num == undefined || num == null) {
            num = 6;
        }
        down = id;
        sdfdf = $("#" + down).prev().attr("id");
        var dsfsd = document.getElementById(sdfdf);
        var height = parseInt(dsfsd.style.height || dsfsd.clientHeight
            || dsfsd.offsetHeight || dsfsd.scrollHeight);
        //每个产品高度40px
        var chise = num * 50;
        if (height < chise) {
            dsfsd.style.height = chise + 'px';
        } else {
            dsfsd.style.height = '125px';
        }
    }
</script>
<script type="text/javascript" id="titleTpl">
{{# if(d.status == 1){ }}
<span class="layui-badge layui-bg-green">已上架</span><br>
{{# }else if(d.status==2){ }}
<span class="layui-badge">未上架</span><br>
{{# }else if(d.status==3){ }}
<span class="layui-badge layui-bg-black">已删除</span><br>
{{# } }}
	<img src="{{ d.proUrl }}" style="width: 80px;height: 80px;margin-top: 10px"/></br>
	产品编号：</br>
	{{ d.proCode}} </br>
</script>
</body>
</html>